﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

    public class CallBack
    {
        public delegate void addfunc(params object[] val);
        public event addfunc _addfunc;

        public delegate void removefunc(params object[] val);
        public event removefunc _removefunc;

        public delegate void updatefunc(params object[] val);
        public event updatefunc _updatefunc;

        public ArrayList _args;
        public ArrayList remove_args;
        public ArrayList update_args;

        public CallBack(addfunc addfunc,removefunc removefunc, ArrayList args,ArrayList removeargs) 
        {
            this._addfunc = addfunc;
            this._removefunc = removefunc;
            _args             = args;
            remove_args = removeargs;
        }
        public CallBack(addfunc addfunc, removefunc removefunc, ArrayList args)
        {
            this._addfunc = addfunc;
            this._removefunc = removefunc;
            _args = args;
        }
        public CallBack(addfunc addfunc, removefunc removefunc, ArrayList args, ArrayList removeargs,updatefunc updatefunc, ArrayList updateargs)
        {
            this._addfunc = addfunc;
            this._removefunc = removefunc;
            _args = args;
            remove_args = removeargs;
            update_args = updateargs;
        }

        public Boolean IsSame(CallBack val) 
        {
            return (val._addfunc == this._addfunc && val._removefunc == this._removefunc);
        }

        public void Call(Boolean isAdd)
        {
            Call(isAdd, false);
        }
        public void Call(Boolean isAdd,Boolean isUpdata)
        {
            Delegate func;
            if (isUpdata) 
            {
                func = _updatefunc;
            }
            else
            {
                if (isAdd)
                {
                    func = _addfunc;
                } 
                else
                {
                    func = _removefunc;
                }
            }
            if (func == null) return;
            
            if (isUpdata)
            {
                _updatefunc(update_args);
            }
            else if (isAdd)
            {
                _addfunc(_args);
            }
            else
            {
                _removefunc(remove_args);
            }
        }
    }